﻿using System.Windows.Controls;
using Red.Controls.ViewModels;

namespace Red.Controls.DataDriven
{
    [InteropControl( "ChunkMaterialObject" )]
    public partial class MaterialControl : UserControl
    {
        public MaterialControl()
        {
            InitializeComponent();
            DataContextChanged += MaterialControl_DataContextChanged;
        }

        private async void MaterialControl_DataContextChanged( object sender, System.Windows.DependencyPropertyChangedEventArgs e )
        {
            DataItem dc = e.NewValue as DataItem;
            if ( dc != null )
            {
                var namesItem = await dc.DigUpSubItemAsync( "_names" );
                _materialsListbox.ItemsSource = namesItem.Children;
                await namesItem.RebuildAsync( false );
            }
        }
    }
}
